/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 */

package pl.droidsonroids.gif;

import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

/**
 * 功能描述
 *
 * @author B71789
 * @since 2020-07-13
 */
public class BaseSavedState extends AbsSavedState {
    /**
     * createFromParcel
     */
    public static final Producer<BaseSavedState> CREATOR
            = new Producer<BaseSavedState>() {
                @Override
                public BaseSavedState createFromParcel(Parcel parcel) {
                    return new BaseSavedState(parcel);
                }
            };
    static final int START_ACTIVITY_REQUESTED_WHO_SAVED = 0b1;
    static final int IS_AUTOFILLED = 0b10;
    static final int AUTOFILL_ID = 0b100;

    // Flags that describe what data in this state is valid
    int mSavedData;
    String mStartActivityRequestWhoSaved;
    boolean mIsAutofilled;
    int mAutofillViewId;

    /**
     * Constructor used when reading from parcel. Reads the state of the superclass.
     *
     * @param source parcel to read from
     */
    public BaseSavedState(Parcel source) {
        this(source, null);
    }

    /**
     * Constructor used when reading from parcel using given class loader.
     * Reads the state of the superclass.
     *
     * @param source parcel to read from
     * @param loader ClassLoader to use for reading
     */
    public BaseSavedState(Parcel source, ClassLoader loader) {
        super(source, loader);
        mSavedData = source.readInt();
        mStartActivityRequestWhoSaved = source.readString();
        mIsAutofilled = source.readBoolean();
        mAutofillViewId = source.readInt();
    }

    /**
     * Constructor called by derived classes when creating their SavedState objects
     *
     * @param superState The state of the superclass of this view
     */
    public BaseSavedState(Sequenceable superState) {
        super(superState);
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        super.writeToParcel(out, flags);

        out.writeInt(mSavedData);
        out.writeString(mStartActivityRequestWhoSaved);
        out.writeBoolean(mIsAutofilled);
        out.writeInt(mAutofillViewId);
    }
}
